<?php
$sub_menu = "230200";
include_once("./_common.php");

auth_check($auth[$sub_menu], "w");

check_token();

if ($w == "") {
    $row = sql_fetch("select * from $g4[member_table] where mb_id = '$mb_id'");
    if (!$row)
	alert("회원ID 가 존재하지 않습니다.");

    if ($cl_paytype == "포인트")
	$cl_id = mw_point_to_cash($mb_id, $cl_cash);
    else
	$cl_id = mw_cash_charge($mb_id, $cl_cash, $cl_content, $cl_payment, $cl_paytype, $cl_paylog, $cl_admin_memo);

    $sql = " update $mw_cash[cash_list_table] set ";
    $sql.= "  cl_domain = '$cl_domain' ";
    $sql.= ", cl_tax_voucher = '$cl_tax_voucher' ";
    $sql.= ", cl_voucher = '$cl_voucher' ";
    $sql.= ", rel_table = '$rel_table' ";
    $sql.= ", rel_id = '$rel_id' ";
    $sql.= " where cl_id = '$cl_id' ";
    sql_query($sql);

    $url = "mw.cash.form.php?w=u&cl_id=$cl_id$qstr";
    $msg = "등록";
}
else if ($w == "u" && $cl_id) {
    $row = sql_fetch("select * from $mw_cash[cash_list_table] where cl_id = '$cl_id'");
    if (!$row)
	alert("자료가 존재하지 않습니다.");

    if ($cl_domain)
	$cl_domain = set_http($cl_domain);

    $sql = " update $mw_cash[cash_list_table] set ";
    $sql.= "  cl_tax_voucher = '$cl_tax_voucher' ";
    $sql.= ", cl_voucher = '$cl_voucher' ";
    $sql.= ", cl_content = '$cl_content' ";
    $sql.= ", cl_admin_memo = '$cl_admin_memo' ";
    $sql.= ", cl_domain = '$cl_domain' ";
    $sql.= ", rel_table = '$rel_table' ";
    $sql.= ", rel_id = '$rel_id' ";
    $sql.= " where cl_id = '$cl_id' ";
    sql_query($sql);

    $url = "mw.cash.form.php?w=u&cl_id=$cl_id$qstr";
    $msg = "수정";
}
else if ($w == "d" && $cl_id) {
    mw_cash_delete($cl_id);

    $url = "mw.cash.list.php?$qstr";
    $msg = "삭제";
}

alert("$msg 되었습니다.", $url);

